package vip.xiaonuo.supplier.modular.business.businessMain.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.business.businessMain.entity.SupplierBusinessMain;
import vip.xiaonuo.supplier.modular.business.businessMain.param.SupplierBusinessMainAddParam;
import vip.xiaonuo.supplier.modular.business.businessMain.param.SupplierBusinessMainEditParam;
import vip.xiaonuo.supplier.modular.business.businessMain.param.SupplierBusinessMainIdParam;
import vip.xiaonuo.supplier.modular.business.businessMain.param.SupplierBusinessMainPageParam;
import vip.xiaonuo.supplier.modular.business.businessMain.service.SupplierBusinessMainService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 业务主表控制器
 *
 * @author Mr.wu
 * @date  2025/03/26 11:03
 */
@Tag(name = "业务主表控制器")
@RestController
@Validated
public class SupplierBusinessMainController {

    @Resource
    private SupplierBusinessMainService supplierBusinessMainService;

    /**
     * 获取业务主表分页
     *
     * @author Mr.wu
     * @date  2025/03/26 11:03
     */
    @Operation(summary = "获取业务主表分页")
    @SaCheckPermission("/supplier/business/businessMain/page")
    @GetMapping("/supplier/business/businessMain/page")
    public CommonResult<Page<SupplierBusinessMain>> page(SupplierBusinessMainPageParam supplierBusinessMainPageParam) {
        return CommonResult.data(supplierBusinessMainService.page(supplierBusinessMainPageParam));
    }

    /**
     * 添加业务主表
     *
     * @author Mr.wu
     * @date  2025/03/26 11:03
     */
    @Operation(summary = "添加业务主表")
    @CommonLog("添加业务主表")
    @SaCheckPermission("/supplier/business/businessMain/add")
    @PostMapping("/supplier/business/businessMain/add")
    public CommonResult<SupplierBusinessMain> add(@RequestBody @Valid JSONObject supplierBusinessJson) {
        return CommonResult.data(supplierBusinessMainService.add(supplierBusinessJson));
    }

    /**
     * 编辑业务主表
     *
     * @author Mr.wu
     * @date  2025/03/26 11:03
     */
    @Operation(summary = "编辑业务主表")
    @CommonLog("编辑业务主表")
    @SaCheckPermission("/supplier/business/businessMain/edit")
    @PostMapping("/supplier/business/businessMain/edit")
    public CommonResult<SupplierBusinessMain> edit(@RequestBody @Valid JSONObject supplierBusinessJson) {
        return CommonResult.data(supplierBusinessMainService.edit(supplierBusinessJson));
    }

    /**
     * 删除业务主表
     *
     * @author Mr.wu
     * @date  2025/03/26 11:03
     */
    @Operation(summary = "删除业务主表")
    @CommonLog("删除业务主表")
    @SaCheckPermission("/supplier/business/businessMain/delete")
    @PostMapping("/supplier/business/businessMain/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierBusinessMainIdParam> supplierBusinessMainIdParamList) {
        supplierBusinessMainService.delete(supplierBusinessMainIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取业务主表详情
     *
     * @author Mr.wu
     * @date  2025/03/26 11:03
     */
    @Operation(summary = "获取业务主表详情")
    @SaCheckPermission("/supplier/business/businessMain/detail")
    @GetMapping("/supplier/business/businessMain/detail")
    public CommonResult<SupplierBusinessMain> detail(@Valid SupplierBusinessMainIdParam supplierBusinessMainIdParam) {
        return CommonResult.data(supplierBusinessMainService.detail(supplierBusinessMainIdParam));
    }

    /**
     * 删除业务主表
     *
     * @author Mr.wu
     * @date  2025/03/26 11:03
     */
    @Operation(summary = "作废业务主表")
    @CommonLog("作废业务主表")
    @SaCheckPermission("/supplier/business/businessMain/cancel")
    @PostMapping("/supplier/business/businessMain/cancel")
    public CommonResult<String> cancel(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                       List<SupplierBusinessMainIdParam> supplierBusinessMainIdParamList) {
        supplierBusinessMainService.cancel(supplierBusinessMainIdParamList);
        return CommonResult.ok();
    }
    /**
     * 获取待结算业务主表分页
     *
     * @author Mr.wu
     * @date  2025/03/26 11:03
     */
    @Operation(summary = "获取待结算业务主表分页")
    @SaCheckPermission("/supplier/business/businessMain/pendingPage")
    @GetMapping("/supplier/business/businessMain/pendingPage")
    public CommonResult<Page<SupplierBusinessMain>> pendingPage(SupplierBusinessMainPageParam supplierBusinessMainPageParam) {
        return CommonResult.data(supplierBusinessMainService.pendingPage(supplierBusinessMainPageParam));
    }
}
